//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    goodsId: "",
    // 
    pageIndex:1,
    state:"",
    recordList:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options);
    this.setData({
      uid: wx.getStorageSync('uid'),
      // goodsId: options.goodsId
    })
    // this.AgentComeAndOutRecord();
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.AgentComeAndOutRecord();
  },

  AgentComeAndOutRecord:function(){
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var goodsId = this.data.goodsId;
    var recordList = this.data.recordList;
    if (pageIndex == 1) {
      wx.showLoading({
        title: '加载中',
      })
    }
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=AgentComeAndOutRecord&PageSize=10&UID=" + uid + "&PageIndex=" + pageIndex + "&GoodsId=" + goodsId),
      success: function (res) {
        console.log(JSON.parse(baseJs.decryUrl(res.data)));
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          recordList.push(json[i])
        }
        that.setData({
          recordList: recordList,
        })     
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        wx.hideLoading();
      }
    })

  },
  // 
})